<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text"id="n1">
    <select id="flag">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
        <option value="%">%</option>
    </select>
    <input type="text" id="n2">
<input type="button" id="btn" value="=">
<input type="text" id="n3">
<script>

    btn.onclick=function(){
        var n1=document.getElementById("n1").value;
        var n2=document.getElementById("n2").value;
        var flag=document.getElementById("flag").value;
        var result="var a=parseFloat(n1);b=parseFloat(n2);return a"+flag+"b";
        // 创建函数
        var fun=new Function("n1","n2",result);
        var n3=fun(n1,n2);;
        document.getElementById("n3").value=n3;
    }
</script>
</body>
</html>